package com.test.demo.controller;

import com.test.demo.model.Account;
import com.test.demo.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/account")
public class AccountController {

    @Autowired
    private AccountService accountServiceImpl;

    @RequestMapping(value = "/list")
    public List<Account> getAccounts(){
        return accountServiceImpl.getAccounts();
    }

    @RequestMapping(value = "/{id}")
    public Account getAccount(@PathVariable("id") int id){
        return accountServiceImpl.getAccountById(id);
    }

    @RequestMapping(value = "/update")
    public String updateAccount(@RequestParam(value = "name") String name,@RequestParam(value = "money") double money, @RequestParam(value = "id") int id){
        Account account=new Account();
        account.setId(id);
        account.setMoney(money);
        account.setName(name);
        return accountServiceImpl.updateAccount(account);
    }
}
